<?php
/*!
	\file class.SimpleDBOFactory.php
	\brief Contains the class definition for the SimpleDBOFactory object
*/

/*!
	\class SimpleDBOFactory
	\author Alex McClung
	\date Created: January 30, 2006
	\date Modified: July 30, 2006
	\brief A static class that creates SimpleDBO objects when given a table name.
	
	Example:
	$foo = SimpleDBOFactory::Create('foo', 1); // Creates a SimpleDBO object for the table 'foo' whose primary key is 1
*/
class SimpleDBOFactory
{
	/*!
		\brief Creates a SimpleDBO object
		\param $table - Name of the table that the SimpleDBO object is connected to.
		\param $id    - (optional) primary key value for a single row in a table, when passed in, values from this row will be loaded into the object's properties
		\returns SimpleDBO class instance; if the id parameter is given and does not match a row in the table, the constructor will return false. If the class is not found, it will also return false.
	*/
	function Create($table, $id=NULL)
	{
		// Put together the class and file name
		$class_name = SIMPLEDBO_CLASSNAME_PREFIX . $table;
		$file_name  = SIMPLEDBO_CLASSFILENAME_PREFIX . $class_name . SIMPLEDBO_CLASSFILENAME_SUFFIX;
		
		// Try and include the file
		require_once(SIMPLEDBO_LIBPATH . $file_name);
		
		// Try and create the object
		return (class_exists($class_name)) ? new $class_name($id) : false;
	}
}

?>